package com.qidian.buy.search.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * Author: 戴着假发的程序员
 * Date: 2023-06-28 14:02
 * company: 起点编程
 * Description: 配置远程调用接口的工具类
 **/
@Configuration
public class RestTemplateConfig {

    @LoadBalanced // 负载均衡
    @Bean
    public RestTemplate restTemplate(ClientHttpRequestFactory factory){
        return new RestTemplate(factory);
    }
    @Bean
    public ClientHttpRequestFactory clientHttpRequestFactory(){
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        // 读取数据的超时时间
        factory.setReadTimeout(5000);//ms
        // 链接的超时时间
        factory.setConnectTimeout(15000);//ms
        return factory;
    }
}
